﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Globalization;
using System.Data;
using System.Data.Common;
using System.Xml;
using System.Text;
using LibHuman;

namespace Human
{
	/// <summary>
	/// Summary description for frmNuocNgoaiSua.
	/// </summary>
	public class frmNuocNgoai : System.Windows.Forms.Form
	{
		private string TSo="", m_user="";		
		private AccessData  mDB=new AccessData ();
        Language lan = new Language();
		public DataSet ds =new DataSet();
		private frmReport  rpt=null ;				
		private DataSet ds1=new DataSet();
        private bool admin = false;
        int flag = 0;
        private string v_manv, v_ho, v_bophan,ten_nd="";
		private System.Windows.Forms.GroupBox groupNN;
		private System.Windows.Forms.Button cmdLuu_NN;
        private System.Windows.Forms.TextBox txtCV_NN;
		private System.Windows.Forms.ComboBox cboDV_NN;
		private System.Windows.Forms.TextBox txtTG_NN;
		private System.Windows.Forms.ComboBox cboQG_NN;
		private System.Windows.Forms.TextBox txtN_NN;
		private System.Windows.Forms.Label label178;
		private System.Windows.Forms.Label label177;
		private System.Windows.Forms.Label label172;
		private System.Windows.Forms.Label label173;
		private System.Windows.Forms.Label label174;
		private System.Windows.Forms.Label label175;
		private System.Windows.Forms.Label label176;
        private System.Windows.Forms.Label label110;
		private System.Windows.Forms.TextBox txtTSo;
		private System.Windows.Forms.Label label27;
		private System.Windows.Forms.ContextMenu dgrNuocNgoaicontextMenu;
		private System.Windows.Forms.MenuItem menuItem1;
		private System.Windows.Forms.MenuItem menuItem2;
		private System.Windows.Forms.ToolTip toolTip1;
        private System.Windows.Forms.Panel panel1;
        private System.ComponentModel.IContainer components;
        private ToolStrip toolStrip3;
        private ToolStripLabel lblHD;
        private Label lblTenPhongCT;
        private Label lblHoTenNVCT;
        private Label label29;
        private Label label28;
        private Label lblMasoNVCT;
        private DataGridView dataGridView1;
		private string ngayct="",sql="";
        private MaskedTextBox txtTN_NN;
        private Button btn_boqua;
        private Button btn_thoat;
        private Button btn_sua;
        private Button btn_them;
        private Button btn_luu;
        private Button btn_huy;
        private DataGridViewTextBoxColumn Column1;
        private DataGridViewTextBoxColumn Column2;
        private DataGridViewTextBoxColumn Column3;
        private DataGridViewTextBoxColumn Column4;
        private DataGridViewTextBoxColumn Column5;
        private DataGridViewTextBoxColumn Column6;
        private DataGridViewTextBoxColumn Column7;
        private DataGridViewTextBoxColumn Column8;
        private DataGridViewTextBoxColumn Column9;
        private TextBox txtid;
        private MaskedTextBox txtDN_NN;

		public frmNuocNgoai(string manv,string hoten,string madv,bool m_admin,string tennd)
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
            lan.Read_Language_to_Xml(this.Name.ToString(), this);
            lan.Changelanguage_to_English(this.Name.ToString(), this);
            m_user = mDB.user;
			lblMasoNVCT.Text=manv;
			lblHoTenNVCT.Text=hoten;
			lblTenPhongCT.Text=madv;
            admin = m_admin;
            ten_nd = tennd;
			tongso();
			sql="select to_char(ngaydenct,'dd/mm/yyyy') as ngay from "+m_user+".hopdong ";
            sql += " where manv='" + manv + "'";		
			ngayct=mDB.get_data(sql).Tables[0].Rows[0]["ngay"].ToString();
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            this.components = new System.ComponentModel.Container();
            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmNuocNgoai));
            this.groupNN = new System.Windows.Forms.GroupBox();
            this.txtid = new System.Windows.Forms.TextBox();
            this.txtDN_NN = new System.Windows.Forms.MaskedTextBox();
            this.txtTN_NN = new System.Windows.Forms.MaskedTextBox();
            this.txtCV_NN = new System.Windows.Forms.TextBox();
            this.cboDV_NN = new System.Windows.Forms.ComboBox();
            this.txtTG_NN = new System.Windows.Forms.TextBox();
            this.cboQG_NN = new System.Windows.Forms.ComboBox();
            this.label178 = new System.Windows.Forms.Label();
            this.label177 = new System.Windows.Forms.Label();
            this.label172 = new System.Windows.Forms.Label();
            this.label173 = new System.Windows.Forms.Label();
            this.label174 = new System.Windows.Forms.Label();
            this.label175 = new System.Windows.Forms.Label();
            this.label176 = new System.Windows.Forms.Label();
            this.txtN_NN = new System.Windows.Forms.TextBox();
            this.cmdLuu_NN = new System.Windows.Forms.Button();
            this.label110 = new System.Windows.Forms.Label();
            this.dgrNuocNgoaicontextMenu = new System.Windows.Forms.ContextMenu();
            this.menuItem1 = new System.Windows.Forms.MenuItem();
            this.menuItem2 = new System.Windows.Forms.MenuItem();
            this.txtTSo = new System.Windows.Forms.TextBox();
            this.label27 = new System.Windows.Forms.Label();
            this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
            this.btn_huy = new System.Windows.Forms.Button();
            this.btn_luu = new System.Windows.Forms.Button();
            this.btn_them = new System.Windows.Forms.Button();
            this.btn_sua = new System.Windows.Forms.Button();
            this.btn_thoat = new System.Windows.Forms.Button();
            this.btn_boqua = new System.Windows.Forms.Button();
            this.panel1 = new System.Windows.Forms.Panel();
            this.toolStrip3 = new System.Windows.Forms.ToolStrip();
            this.lblHD = new System.Windows.Forms.ToolStripLabel();
            this.lblTenPhongCT = new System.Windows.Forms.Label();
            this.lblHoTenNVCT = new System.Windows.Forms.Label();
            this.label29 = new System.Windows.Forms.Label();
            this.label28 = new System.Windows.Forms.Label();
            this.lblMasoNVCT = new System.Windows.Forms.Label();
            this.dataGridView1 = new System.Windows.Forms.DataGridView();
            this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column4 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column5 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column6 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column7 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column8 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column9 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.groupNN.SuspendLayout();
            this.panel1.SuspendLayout();
            this.toolStrip3.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
            this.SuspendLayout();
            // 
            // groupNN
            // 
            this.groupNN.Controls.Add(this.txtid);
            this.groupNN.Controls.Add(this.txtDN_NN);
            this.groupNN.Controls.Add(this.txtTN_NN);
            this.groupNN.Controls.Add(this.txtCV_NN);
            this.groupNN.Controls.Add(this.cboDV_NN);
            this.groupNN.Controls.Add(this.txtTG_NN);
            this.groupNN.Controls.Add(this.cboQG_NN);
            this.groupNN.Controls.Add(this.label178);
            this.groupNN.Controls.Add(this.label177);
            this.groupNN.Controls.Add(this.label172);
            this.groupNN.Controls.Add(this.label173);
            this.groupNN.Controls.Add(this.label174);
            this.groupNN.Controls.Add(this.label175);
            this.groupNN.Controls.Add(this.label176);
            this.groupNN.Controls.Add(this.txtN_NN);
            this.groupNN.Dock = System.Windows.Forms.DockStyle.Bottom;
            this.groupNN.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.groupNN.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(160)))));
            this.groupNN.Location = new System.Drawing.Point(0, 472);
            this.groupNN.Name = "groupNN";
            this.groupNN.Size = new System.Drawing.Size(839, 72);
            this.groupNN.TabIndex = 100;
            this.groupNN.TabStop = false;
            // 
            // txtid
            // 
            this.txtid.Location = new System.Drawing.Point(651, 11);
            this.txtid.Name = "txtid";
            this.txtid.Size = new System.Drawing.Size(59, 20);
            this.txtid.TabIndex = 220;
            this.txtid.Visible = false;
            // 
            // txtDN_NN
            // 
            this.txtDN_NN.BackColor = System.Drawing.Color.White;
            this.txtDN_NN.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.txtDN_NN.ForeColor = System.Drawing.Color.Navy;
            this.txtDN_NN.Location = new System.Drawing.Point(417, 35);
            this.txtDN_NN.Mask = "00/00/0000";
            this.txtDN_NN.Name = "txtDN_NN";
            this.txtDN_NN.Size = new System.Drawing.Size(85, 21);
            this.txtDN_NN.TabIndex = 65;
            this.txtDN_NN.ValidatingType = typeof(System.DateTime);
            this.txtDN_NN.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtDN_NN_KeyDown);
            this.txtDN_NN.Validated += new System.EventHandler(this.txtDN_NN_Validated);
            // 
            // txtTN_NN
            // 
            this.txtTN_NN.BackColor = System.Drawing.Color.White;
            this.txtTN_NN.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.txtTN_NN.ForeColor = System.Drawing.Color.Navy;
            this.txtTN_NN.Location = new System.Drawing.Point(329, 35);
            this.txtTN_NN.Mask = "00/00/0000";
            this.txtTN_NN.Name = "txtTN_NN";
            this.txtTN_NN.Size = new System.Drawing.Size(85, 21);
            this.txtTN_NN.TabIndex = 64;
            this.txtTN_NN.ValidatingType = typeof(System.DateTime);
            this.txtTN_NN.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtTN_NN_KeyDown);
            this.txtTN_NN.Validated += new System.EventHandler(this.txtTN_NN_Validated);
            // 
            // txtCV_NN
            // 
            this.txtCV_NN.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.txtCV_NN.BackColor = System.Drawing.Color.White;
            this.txtCV_NN.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.txtCV_NN.ForeColor = System.Drawing.Color.DarkBlue;
            this.txtCV_NN.Location = new System.Drawing.Point(508, 33);
            this.txtCV_NN.MaxLength = 50;
            this.txtCV_NN.Name = "txtCV_NN";
            this.txtCV_NN.Size = new System.Drawing.Size(325, 21);
            this.txtCV_NN.TabIndex = 66;
            this.txtCV_NN.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtCV_NN_KeyDown);
            // 
            // cboDV_NN
            // 
            this.cboDV_NN.BackColor = System.Drawing.Color.White;
            this.cboDV_NN.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.cboDV_NN.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.cboDV_NN.ForeColor = System.Drawing.Color.DarkBlue;
            this.cboDV_NN.Location = new System.Drawing.Point(251, 35);
            this.cboDV_NN.Name = "cboDV_NN";
            this.cboDV_NN.Size = new System.Drawing.Size(75, 21);
            this.cboDV_NN.TabIndex = 63;
            this.cboDV_NN.Validated += new System.EventHandler(this.cboDV_NN_Validated);
            this.cboDV_NN.KeyDown += new System.Windows.Forms.KeyEventHandler(this.cboDV_NN_KeyDown);
            // 
            // txtTG_NN
            // 
            this.txtTG_NN.BackColor = System.Drawing.Color.White;
            this.txtTG_NN.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.txtTG_NN.ForeColor = System.Drawing.Color.DarkBlue;
            this.txtTG_NN.Location = new System.Drawing.Point(182, 35);
            this.txtTG_NN.MaxLength = 5;
            this.txtTG_NN.Name = "txtTG_NN";
            this.txtTG_NN.Size = new System.Drawing.Size(66, 21);
            this.txtTG_NN.TabIndex = 62;
            this.txtTG_NN.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtTG_NN_KeyDown);
            this.txtTG_NN.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtN_NN_KeyPress);
            // 
            // cboQG_NN
            // 
            this.cboQG_NN.BackColor = System.Drawing.Color.White;
            this.cboQG_NN.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.cboQG_NN.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.cboQG_NN.ForeColor = System.Drawing.Color.DarkBlue;
            this.cboQG_NN.Location = new System.Drawing.Point(67, 35);
            this.cboQG_NN.Name = "cboQG_NN";
            this.cboQG_NN.Size = new System.Drawing.Size(112, 21);
            this.cboQG_NN.TabIndex = 61;
            this.cboQG_NN.KeyDown += new System.Windows.Forms.KeyEventHandler(this.cboQG_NN_KeyDown);
            // 
            // label178
            // 
            this.label178.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label178.ForeColor = System.Drawing.Color.DarkBlue;
            this.label178.Location = new System.Drawing.Point(509, 15);
            this.label178.Name = "label178";
            this.label178.Size = new System.Drawing.Size(59, 13);
            this.label178.TabIndex = 59;
            this.label178.Text = "Công Việc ";
            this.label178.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // label177
            // 
            this.label177.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label177.ForeColor = System.Drawing.Color.DarkBlue;
            this.label177.Location = new System.Drawing.Point(418, 18);
            this.label177.Name = "label177";
            this.label177.Size = new System.Drawing.Size(58, 13);
            this.label177.TabIndex = 58;
            this.label177.Text = "Đến Ngày ";
            this.label177.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // label172
            // 
            this.label172.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label172.ForeColor = System.Drawing.Color.DarkBlue;
            this.label172.Location = new System.Drawing.Point(331, 17);
            this.label172.Name = "label172";
            this.label172.Size = new System.Drawing.Size(51, 13);
            this.label172.TabIndex = 57;
            this.label172.Text = "Từ Ngày ";
            this.label172.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // label173
            // 
            this.label173.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label173.ForeColor = System.Drawing.Color.DarkBlue;
            this.label173.Location = new System.Drawing.Point(250, 17);
            this.label173.Name = "label173";
            this.label173.Size = new System.Drawing.Size(42, 13);
            this.label173.TabIndex = 55;
            this.label173.Text = "Đơn Vị ";
            this.label173.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // label174
            // 
            this.label174.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label174.ForeColor = System.Drawing.Color.DarkBlue;
            this.label174.Location = new System.Drawing.Point(182, 17);
            this.label174.Name = "label174";
            this.label174.Size = new System.Drawing.Size(56, 13);
            this.label174.TabIndex = 53;
            this.label174.Text = "Thời Gian ";
            this.label174.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // label175
            // 
            this.label175.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label175.ForeColor = System.Drawing.Color.DarkBlue;
            this.label175.Location = new System.Drawing.Point(70, 17);
            this.label175.Name = "label175";
            this.label175.Size = new System.Drawing.Size(55, 13);
            this.label175.TabIndex = 51;
            this.label175.Text = "Quốc Gia ";
            this.label175.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // label176
            // 
            this.label176.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label176.ForeColor = System.Drawing.Color.DarkBlue;
            this.label176.Location = new System.Drawing.Point(12, 17);
            this.label176.Name = "label176";
            this.label176.Size = new System.Drawing.Size(32, 13);
            this.label176.TabIndex = 49;
            this.label176.Text = "Năm ";
            this.label176.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // txtN_NN
            // 
            this.txtN_NN.BackColor = System.Drawing.Color.White;
            this.txtN_NN.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.txtN_NN.ForeColor = System.Drawing.Color.DarkBlue;
            this.txtN_NN.Location = new System.Drawing.Point(8, 35);
            this.txtN_NN.MaxLength = 4;
            this.txtN_NN.Name = "txtN_NN";
            this.txtN_NN.Size = new System.Drawing.Size(56, 21);
            this.txtN_NN.TabIndex = 60;
            this.txtN_NN.Validated += new System.EventHandler(this.txtN_NN_Validated);
            this.txtN_NN.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtN_NN_KeyDown);
            this.txtN_NN.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtN_NN_KeyPress);
            // 
            // cmdLuu_NN
            // 
            this.cmdLuu_NN.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.cmdLuu_NN.ForeColor = System.Drawing.Color.Blue;
            this.cmdLuu_NN.Location = new System.Drawing.Point(660, 19);
            this.cmdLuu_NN.Name = "cmdLuu_NN";
            this.cmdLuu_NN.Size = new System.Drawing.Size(64, 23);
            this.cmdLuu_NN.TabIndex = 67;
            this.cmdLuu_NN.Text = "Lưu";
            this.cmdLuu_NN.Visible = false;
            // 
            // label110
            // 
            this.label110.Dock = System.Windows.Forms.DockStyle.Top;
            this.label110.Font = new System.Drawing.Font("Microsoft Sans Serif", 15.75F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Underline))), System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label110.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(160)))));
            this.label110.Location = new System.Drawing.Point(0, 51);
            this.label110.Name = "label110";
            this.label110.Size = new System.Drawing.Size(839, 32);
            this.label110.TabIndex = 99;
            this.label110.Text = "TÌNH HÌNH CÔNG TÁC NƯỚC NGOÀI";
            this.label110.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            // 
            // dgrNuocNgoaicontextMenu
            // 
            this.dgrNuocNgoaicontextMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
            this.menuItem1,
            this.menuItem2});
            // 
            // menuItem1
            // 
            this.menuItem1.Index = 0;
            this.menuItem1.Text = "Thêm";
            this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
            // 
            // menuItem2
            // 
            this.menuItem2.Index = 1;
            this.menuItem2.Text = "Hủy";
            this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
            // 
            // txtTSo
            // 
            this.txtTSo.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.txtTSo.ForeColor = System.Drawing.Color.Red;
            this.txtTSo.Location = new System.Drawing.Point(714, 9);
            this.txtTSo.Name = "txtTSo";
            this.txtTSo.Size = new System.Drawing.Size(64, 22);
            this.txtTSo.TabIndex = 101;
            this.txtTSo.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
            this.txtTSo.Visible = false;
            this.txtTSo.WordWrap = false;
            // 
            // label27
            // 
            this.label27.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label27.ForeColor = System.Drawing.Color.Blue;
            this.label27.Location = new System.Drawing.Point(648, 14);
            this.label27.Name = "label27";
            this.label27.Size = new System.Drawing.Size(63, 13);
            this.label27.TabIndex = 103;
            this.label27.Text = "Tổng  Số ";
            this.label27.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.label27.Visible = false;
            // 
            // btn_huy
            // 
            this.btn_huy.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btn_huy.Image = global::Human.Properties.Resources.DeleteFilter;
            this.btn_huy.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.btn_huy.Location = new System.Drawing.Point(458, 5);
            this.btn_huy.Name = "btn_huy";
            this.btn_huy.Size = new System.Drawing.Size(65, 28);
            this.btn_huy.TabIndex = 5;
            this.btn_huy.Text = "   &Hủy";
            this.toolTip1.SetToolTip(this.btn_huy, "Alt+H");
            this.btn_huy.UseVisualStyleBackColor = true;
            this.btn_huy.Click += new System.EventHandler(this.btn_huy_Click);
            // 
            // btn_luu
            // 
            this.btn_luu.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btn_luu.Image = global::Human.Properties.Resources.save;
            this.btn_luu.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.btn_luu.Location = new System.Drawing.Point(311, 5);
            this.btn_luu.Name = "btn_luu";
            this.btn_luu.Size = new System.Drawing.Size(65, 28);
            this.btn_luu.TabIndex = 3;
            this.btn_luu.Text = "   &Lưu";
            this.toolTip1.SetToolTip(this.btn_luu, "Alt+L");
            this.btn_luu.UseVisualStyleBackColor = true;
            this.btn_luu.Click += new System.EventHandler(this.btn_luu_Click);
            this.btn_luu.KeyDown += new System.Windows.Forms.KeyEventHandler(this.btn_luu_KeyDown);
            // 
            // btn_them
            // 
            this.btn_them.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btn_them.Image = global::Human.Properties.Resources.add;
            this.btn_them.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.btn_them.Location = new System.Drawing.Point(170, 5);
            this.btn_them.Name = "btn_them";
            this.btn_them.Size = new System.Drawing.Size(65, 28);
            this.btn_them.TabIndex = 1;
            this.btn_them.Text = "    &Thêm";
            this.toolTip1.SetToolTip(this.btn_them, "Alt+T");
            this.btn_them.UseVisualStyleBackColor = true;
            this.btn_them.Click += new System.EventHandler(this.btn_them_Click);
            this.btn_them.KeyDown += new System.Windows.Forms.KeyEventHandler(this.btn_them_KeyDown);
            // 
            // btn_sua
            // 
            this.btn_sua.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btn_sua.Image = global::Human.Properties.Resources.quick_edit;
            this.btn_sua.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.btn_sua.Location = new System.Drawing.Point(241, 5);
            this.btn_sua.Name = "btn_sua";
            this.btn_sua.Size = new System.Drawing.Size(65, 28);
            this.btn_sua.TabIndex = 2;
            this.btn_sua.Text = "  &Sửa";
            this.toolTip1.SetToolTip(this.btn_sua, "Alt+S");
            this.btn_sua.UseVisualStyleBackColor = true;
            this.btn_sua.Click += new System.EventHandler(this.btn_sua_Click);
            // 
            // btn_thoat
            // 
            this.btn_thoat.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btn_thoat.Image = global::Human.Properties.Resources.close_r;
            this.btn_thoat.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.btn_thoat.Location = new System.Drawing.Point(529, 5);
            this.btn_thoat.Name = "btn_thoat";
            this.btn_thoat.Size = new System.Drawing.Size(75, 28);
            this.btn_thoat.TabIndex = 6;
            this.btn_thoat.Text = "&Kết thúc";
            this.btn_thoat.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.toolTip1.SetToolTip(this.btn_thoat, "Alt+K");
            this.btn_thoat.UseVisualStyleBackColor = true;
            this.btn_thoat.Click += new System.EventHandler(this.btn_thoat_Click);
            // 
            // btn_boqua
            // 
            this.btn_boqua.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btn_boqua.Image = global::Human.Properties.Resources.undo_ok;
            this.btn_boqua.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.btn_boqua.Location = new System.Drawing.Point(382, 5);
            this.btn_boqua.Name = "btn_boqua";
            this.btn_boqua.Size = new System.Drawing.Size(70, 28);
            this.btn_boqua.TabIndex = 4;
            this.btn_boqua.Text = "&Bỏ qua";
            this.btn_boqua.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.toolTip1.SetToolTip(this.btn_boqua, "Alt+B");
            this.btn_boqua.UseVisualStyleBackColor = true;
            this.btn_boqua.Click += new System.EventHandler(this.btn_boqua_Click);
            // 
            // panel1
            // 
            this.panel1.Controls.Add(this.btn_huy);
            this.panel1.Controls.Add(this.btn_luu);
            this.panel1.Controls.Add(this.btn_them);
            this.panel1.Controls.Add(this.btn_sua);
            this.panel1.Controls.Add(this.btn_thoat);
            this.panel1.Controls.Add(this.btn_boqua);
            this.panel1.Controls.Add(this.txtTSo);
            this.panel1.Controls.Add(this.label27);
            this.panel1.Dock = System.Windows.Forms.DockStyle.Bottom;
            this.panel1.Location = new System.Drawing.Point(0, 544);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(839, 36);
            this.panel1.TabIndex = 105;
            // 
            // toolStrip3
            // 
            this.toolStrip3.AutoSize = false;
            this.toolStrip3.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(160)))));
            this.toolStrip3.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.lblHD});
            this.toolStrip3.LayoutStyle = System.Windows.Forms.ToolStripLayoutStyle.HorizontalStackWithOverflow;
            this.toolStrip3.Location = new System.Drawing.Point(0, 0);
            this.toolStrip3.Name = "toolStrip3";
            this.toolStrip3.Size = new System.Drawing.Size(839, 51);
            this.toolStrip3.TabIndex = 215;
            this.toolStrip3.Text = "toolStrip3";
            // 
            // lblHD
            // 
            this.lblHD.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(160)))));
            this.lblHD.Font = new System.Drawing.Font("Tahoma", 15F, System.Drawing.FontStyle.Bold);
            this.lblHD.ForeColor = System.Drawing.Color.White;
            this.lblHD.Name = "lblHD";
            this.lblHD.Size = new System.Drawing.Size(0, 48);
            // 
            // lblTenPhongCT
            // 
            this.lblTenPhongCT.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(160)))));
            this.lblTenPhongCT.Font = new System.Drawing.Font("Microsoft Sans Serif", 11F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lblTenPhongCT.ForeColor = System.Drawing.SystemColors.HighlightText;
            this.lblTenPhongCT.Location = new System.Drawing.Point(657, 5);
            this.lblTenPhongCT.Name = "lblTenPhongCT";
            this.lblTenPhongCT.Size = new System.Drawing.Size(138, 40);
            this.lblTenPhongCT.TabIndex = 219;
            this.lblTenPhongCT.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            // 
            // lblHoTenNVCT
            // 
            this.lblHoTenNVCT.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(160)))));
            this.lblHoTenNVCT.Font = new System.Drawing.Font("Microsoft Sans Serif", 13F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lblHoTenNVCT.ForeColor = System.Drawing.SystemColors.HighlightText;
            this.lblHoTenNVCT.Location = new System.Drawing.Point(275, 5);
            this.lblHoTenNVCT.Name = "lblHoTenNVCT";
            this.lblHoTenNVCT.Size = new System.Drawing.Size(280, 40);
            this.lblHoTenNVCT.TabIndex = 218;
            this.lblHoTenNVCT.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // label29
            // 
            this.label29.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(160)))));
            this.label29.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label29.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;
            this.label29.Location = new System.Drawing.Point(219, 5);
            this.label29.Name = "label29";
            this.label29.Size = new System.Drawing.Size(56, 40);
            this.label29.TabIndex = 217;
            this.label29.Text = "Họ tên ";
            this.label29.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            // 
            // label28
            // 
            this.label28.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(160)))));
            this.label28.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label28.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;
            this.label28.Location = new System.Drawing.Point(29, 5);
            this.label28.Name = "label28";
            this.label28.Size = new System.Drawing.Size(56, 40);
            this.label28.TabIndex = 221;
            this.label28.Text = "Mã số";
            this.label28.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            // 
            // lblMasoNVCT
            // 
            this.lblMasoNVCT.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(160)))));
            this.lblMasoNVCT.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lblMasoNVCT.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;
            this.lblMasoNVCT.Location = new System.Drawing.Point(87, 6);
            this.lblMasoNVCT.Name = "lblMasoNVCT";
            this.lblMasoNVCT.Size = new System.Drawing.Size(95, 40);
            this.lblMasoNVCT.TabIndex = 220;
            this.lblMasoNVCT.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            // 
            // dataGridView1
            // 
            this.dataGridView1.BackgroundColor = System.Drawing.Color.White;
            dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
            dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control;
            dataGridViewCellStyle1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText;
            dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight;
            dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
            dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
            this.dataGridView1.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1;
            this.dataGridView1.ColumnHeadersHeight = 25;
            this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
            this.Column1,
            this.Column2,
            this.Column3,
            this.Column4,
            this.Column5,
            this.Column6,
            this.Column7,
            this.Column8,
            this.Column9});
            this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.dataGridView1.Location = new System.Drawing.Point(0, 83);
            this.dataGridView1.Name = "dataGridView1";
            this.dataGridView1.RowHeadersWidth = 25;
            this.dataGridView1.Size = new System.Drawing.Size(839, 389);
            this.dataGridView1.TabIndex = 222;
            this.dataGridView1.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellClick);
            this.dataGridView1.CurrentCellChanged += new System.EventHandler(this.dataGridView1_CurrentCellChanged);
            // 
            // Column1
            // 
            this.Column1.DataPropertyName = "nam";
            this.Column1.HeaderText = "Năm";
            this.Column1.Name = "Column1";
            this.Column1.Width = 80;
            // 
            // Column2
            // 
            this.Column2.DataPropertyName = "tenqg";
            this.Column2.HeaderText = "Quốc gia";
            this.Column2.Name = "Column2";
            this.Column2.Width = 150;
            // 
            // Column3
            // 
            this.Column3.DataPropertyName = "t_gian";
            this.Column3.HeaderText = "Thời gian";
            this.Column3.Name = "Column3";
            this.Column3.Width = 80;
            // 
            // Column4
            // 
            this.Column4.DataPropertyName = "dvtgian";
            this.Column4.HeaderText = "Đơn vị";
            this.Column4.Name = "Column4";
            // 
            // Column5
            // 
            this.Column5.DataPropertyName = "tu_ngay";
            this.Column5.HeaderText = "Từ ngày";
            this.Column5.Name = "Column5";
            // 
            // Column6
            // 
            this.Column6.DataPropertyName = "den_ngay";
            this.Column6.HeaderText = "Đến ngày";
            this.Column6.Name = "Column6";
            // 
            // Column7
            // 
            this.Column7.DataPropertyName = "lamgi";
            this.Column7.HeaderText = "Công việc";
            this.Column7.Name = "Column7";
            this.Column7.Width = 200;
            // 
            // Column8
            // 
            this.Column8.DataPropertyName = "manv";
            this.Column8.HeaderText = "Mã NV";
            this.Column8.Name = "Column8";
            this.Column8.Visible = false;
            // 
            // Column9
            // 
            this.Column9.DataPropertyName = "maqgia";
            this.Column9.HeaderText = "Mã quốc gia";
            this.Column9.Name = "Column9";
            this.Column9.Visible = false;
            // 
            // frmNuocNgoai
            // 
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
            this.ClientSize = new System.Drawing.Size(839, 580);
            this.Controls.Add(this.dataGridView1);
            this.Controls.Add(this.label110);
            this.Controls.Add(this.groupNN);
            this.Controls.Add(this.lblTenPhongCT);
            this.Controls.Add(this.lblHoTenNVCT);
            this.Controls.Add(this.label29);
            this.Controls.Add(this.label28);
            this.Controls.Add(this.lblMasoNVCT);
            this.Controls.Add(this.toolStrip3);
            this.Controls.Add(this.panel1);
            this.Controls.Add(this.cmdLuu_NN);
            this.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(160)))));
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.MaximizeBox = false;
            this.Name = "frmNuocNgoai";
            this.ShowInTaskbar = false;
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Hồ sơ nhân viên";
            this.Load += new System.EventHandler(this.frmNuocNgoaiSua_Load);
            this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.frmNuocNgoai_KeyDown);
            this.groupNN.ResumeLayout(false);
            this.groupNN.PerformLayout();
            this.panel1.ResumeLayout(false);
            this.panel1.PerformLayout();
            this.toolStrip3.ResumeLayout(false);
            this.toolStrip3.PerformLayout();
            ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
            this.ResumeLayout(false);

		}
		#endregion

		
		public void tongso()
		{
			try
			{
				ds=mDB.f_countNV();
				TSo=ds.Tables[0].Rows[0][0].ToString();
				txtTSo.Text="";
				txtTSo.Text=TSo.ToString();
			}
			catch{}
		}
		
		
		

		private void txtN_NN_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Enter)
				SendKeys.Send("{Tab}{F4}");		
		}

		private void txtN_NN_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
		{
            if ((e.KeyChar < '0' || e.KeyChar > '9') && e.KeyChar != '\b')
                e.KeyChar = '\0';
		}

		private void txtN_NN_Validated(object sender, System.EventArgs e)
		{
			try
			{
                if (txtN_NN.Text.Trim().Length == 4)
                {
                    int dd=0,mm=0,yy=0;				
				    dd=int.Parse(ngayct.Substring(0,2));
				    mm=int.Parse(ngayct.Substring(3,2));
				    yy=int.Parse(ngayct.Substring(6,4));
                    if (int.Parse(txtN_NN.Text.ToString()) < yy)
                    {
                        MessageBox.Show("Năm đi công tác nước ngoài phải lớn hơn năm đến công tác " + yy, "Thông Báo");
                        txtN_NN.Focus();
                        return;
                    }
                }                
                else
                {
                    MessageBox.Show("Nhập năm không hợp lệ", "Thông báo!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txtN_NN.Focus();
                    return;
                }
			}
			catch{}
		}

		private void cboQG_NN_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Enter)
				//SendKeys.Send("{Tab}");
				txtTG_NN.Focus();
		}

		private void txtTG_NN_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			try{
			if (e.KeyCode == Keys.Enter)
			{
				if(txtTG_NN.Text=="")
				{
					MessageBox.Show("Yêu cầu nhập thời gian đi",this.Text);
					txtTG_NN.Focus();
					return; 
				}				
				SendKeys.Send("{Tab}{F4}");
			}
		}  
		catch{}
	}

		private void txtTG_NN_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
		{
			
			if(e.KeyChar==8)
				e.Handled=false;
		}

		private void cboDV_NN_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Enter)
				SendKeys.Send("{Tab}");
				//txtTN_NN.Focus();
		}

		private void txtTN_NN_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Enter)
				SendKeys.Send("{Tab}");
		}

		private void txtTN_NN_Validated(object sender, System.EventArgs e)
		{
			
            txtTN_NN.Text = txtTN_NN.Text.Trim();
            if (txtTN_NN.Text == "  /  /")
            {                
				MessageBox.Show("Nhập ngày bắt đầu đi công tác",AccessData.Msg,MessageBoxButtons.OK,MessageBoxIcon.Warning);
				//txtTN_NN.Focus();
                return;			
            }
            else
			{
				if(!mDB.kiemtrangayhople(txtTN_NN.Text.Trim()))
				{
					txtTN_NN.Focus();	
                    return ;
				}
				int ddns=0,mmns=0,yyns=0;				
				try
				{					
					ddns=int.Parse(txtTN_NN.Text.Substring(0,2));
					mmns=int.Parse(txtTN_NN.Text.Substring(3,2));
					yyns=int.Parse(txtTN_NN.Text.Substring(6,4));
				}
				catch{}

				int dd=0,mm=0,yy=0;				
				try
				{					
					dd=int.Parse(ngayct.Substring(0,2));
					mm=int.Parse(ngayct.Substring(3,2));
					yy=int.Parse(ngayct.Substring(6,4));
				}
				catch{}
				try
				{
					int nng=int.Parse(txtN_NN.Text);
					if(yyns>nng || yyns<nng)
					{
						MessageBox.Show("Năm phải bằng "+txtN_NN.Text);
						txtTN_NN.Focus();
						return;
					}
					if(yyns<yy)
					{
						MessageBox.Show("Ngày đến công tác " + ngayct + " phải nhỏ hơn từ ngày công tác nước ngoài","Thông Báo");
						txtTN_NN.Focus();
						return;
					}
					
					if(yyns==yy)
					{
						if(mmns<mm)
						{
							MessageBox.Show("Ngày đến công tác " + ngayct + " phải nhỏ hơn từ ngày công tác nước ngoài","Thông Báo");
							txtTN_NN.Focus();
							return;
						}
						if(mmns==mm)
						{
							if(ddns<dd)
							{
								MessageBox.Show("Ngày đến công tác " + ngayct + " phải nhỏ hơn từ ngày công tác nước ngoài","Thông Báo");
								txtTN_NN.Focus();
								return;
							}
						}
					}
				}
				catch{}

				int temp=0;
				if(txtTG_NN.Text.Trim()!="")
					temp=int.Parse(txtTG_NN.Text);		
				DateTime d1,d2;
				d1=new DateTime(yyns,mmns,ddns);
				if(cboDV_NN.SelectedIndex==0)
				{
					d2=d1.AddMonths(temp);
					txtDN_NN.Text=d2.ToString("dd/MM/yyyy",null);
				}
				if(cboDV_NN.SelectedIndex==1)
				{
					d2=d1.AddYears(temp);
					txtDN_NN.Text=d2.ToString("dd/MM/yyyy",null);
				}
				if(cboDV_NN.SelectedIndex==2)
				{
					d2=d1.AddDays(temp);
					txtDN_NN.Text=d2.ToString("dd/MM/yyyy",null);
				}
			}			
		}

		private void txtDN_NN_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Enter)
				SendKeys.Send("{Tab}");
		}

		private void txtCV_NN_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Enter)
			{
				btn_luu.Focus();							
			}
		}

		private bool kiemtraNN()
		{			
			if(txtTG_NN.Text=="")
			{
				MessageBox.Show("Nhập thời gian đi nước ngoài","Thông Báo");
				txtTG_NN.Focus();
				return false;
			}
			if(txtTN_NN.Text=="")
			{
				MessageBox.Show("Nhập từ ngày đi nước ngoài","Thông Báo");
				txtTN_NN.Focus();
				return false;
			}
			if(txtDN_NN.Text=="")
			{
				MessageBox.Show("Nhập đến ngày đi nước ngoài","Thông Báo");
				txtDN_NN.Focus();
				return false;
			}
			if(txtCV_NN.Text=="")
			{
				MessageBox.Show("Nhập công việc phải đi","Thông Báo");
				txtCV_NN.Focus();
				return false;
			}
			return true;
		}
		
		private void dgrTHDiCTNN_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Enter)
				SendKeys.Send("{Tab}");
		}

		private void menuItem1_Click(object sender, System.EventArgs e)
		{
			groupNN.Visible=true;			
			txtN_NN.Focus();
			cboQG_NN.DisplayMember="tenqg";
			cboQG_NN.ValueMember="maqg";
			cboQG_NN.DataSource=mDB.get_data("SELECT * FROM quocgia").Tables[0];
			
			cboDV_NN.DisplayMember="ten";
			cboDV_NN.ValueMember="ten";
			cboDV_NN.DataSource=mDB.get_data("SELECT * FROM dmThoiGian").Tables[0];
			txtN_NN.Text="";
			cboQG_NN.SelectedIndex=-1;
			txtTG_NN.Text="";
			cboDV_NN.SelectedIndex=-1;
			txtTN_NN.Text="";
			txtDN_NN.Text="";
			txtCV_NN.Text="";
		}

		private void load_griddinuocngoai()
		{
			string ma_nv;       
			try 
			{
				ma_nv=lblMasoNVCT.Text;
				DataSet ads =mDB.f_dinuocngoai(ma_nv);
                dataGridView1.DataSource = ads.Tables[0];                
			}
			catch{}
		}

		private void menuItem2_Click(object sender, System.EventArgs e)
		{
            string ma_nv = "";
			ma_nv=lblMasoNVCT.Text;            
		}

		private void butKetThuc_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void cboDV_NN_Validated(object sender, System.EventArgs e)
		{
			try
			{
                if (cboDV_NN.SelectedIndex == -1)
                {
                    //MessageBox.Show("Yêu cầu chọn đơn vị thời gian đi nước ngoài",this.Text);
                    cboDV_NN.Focus();
                    SendKeys.Send("{F4}");
                    return;
                }
				//txtTN_NN_Validated(null,null);
			}
			catch{}
		}
        private void btn_boqua_Click(object sender, EventArgs e)
        {
            Ena_control(true);
            Ena_textbox(false);
            flag = 0;
        }		
		private void Ena_control(bool ena)
		{
			btn_sua.Enabled=!ena; 
			btn_them.Enabled=ena;
			btn_luu.Enabled=!ena;
			btn_boqua.Enabled=!ena;
			btn_huy.Enabled=!ena;
            btn_thoat.Enabled = ena;
		}
		private void Ena_textbox(bool ena)
		{
			txtN_NN.Enabled=ena;
			cboDV_NN.Enabled=ena;
			cboQG_NN.Enabled=ena;
			txtTN_NN.Enabled=ena;
			txtDN_NN.Enabled=ena;
			txtTG_NN.Enabled=ena;
			txtCV_NN.Enabled=ena;
		}
		private void clear_Text()
		{
			txtN_NN.Clear();
			cboDV_NN.SelectedIndex=-1;
			cboQG_NN.SelectedValue=-1;
			txtTN_NN.Clear();
			txtDN_NN.Clear();
			txtTG_NN.Clear();
			txtCV_NN.Clear();
		}
	
		private void saveData()
		{
			string ma_nv,quoc_gia,dvtg,t_ngay="",d_ngay="",cv;
			int  nam_,thoi_gian;
            decimal m_id = 0;
			if(!kiemtraNN()) return;
			ma_nv=lblMasoNVCT.Text;				
			nam_=(txtN_NN.Text.ToString()=="")?0:int.Parse(txtN_NN.Text.ToString());
			if(cboQG_NN.SelectedIndex==-1) cboQG_NN.SelectedIndex=0;
			quoc_gia=cboQG_NN.SelectedValue.ToString();
			thoi_gian=(txtTG_NN.Text.ToString()=="")?0:int.Parse(txtTG_NN.Text.ToString());
			if(cboDV_NN.SelectedIndex==-1) cboDV_NN.SelectedIndex=0;
			    dvtg=cboDV_NN.SelectedValue.ToString();
            if(txtTN_NN.Text.Trim()!="/  /")
			    t_ngay= txtTN_NN.Text.Trim();
            if(txtDN_NN.Text.Trim()!="/  /") 
			    d_ngay=txtDN_NN.Text.Trim();
          
			cv=txtCV_NN.Text;
            if (flag == 0)
            {
                m_id = get_id();
            }
            else
            {
                if (txtid.Text != "")
                    m_id = decimal.Parse(txtid.Text.ToString());
            }
            mDB.upd_Nuocngoai(ma_nv, nam_, quoc_gia, thoi_gian, dvtg, t_ngay, d_ngay, cv, ten_nd, m_id);
			load_griddinuocngoai();
		
			Ena_control(true);
			Ena_textbox(false);	
			btn_them.Focus();
		}
        decimal get_id()
        {
            decimal m_id = 0;
            sql = "select max(id)+1 as max_id from " + m_user + ".xuatcanh ";
            DataSet dst = new DataSet();
            try
            {
                dst = mDB.get_data(sql);
                if (dst.Tables[0].Rows[0]["max_id"].ToString() != "")
                {
                    m_id = decimal.Parse(dst.Tables[0].Rows[0]["max_id"].ToString());
                }
                else
                    m_id = 1;
            }
            catch
            {
                m_id = 1;
            }
            return m_id;
        }
		private void frmNuocNgoaiSua_Load(object sender, System.EventArgs e)
		{			
            load_dm();			
            load_griddinuocngoai();
            Ena_control(true);
			Ena_textbox(false);		
		}
		private void load_dm()
		{
			DataSet ds=mDB.get_data("SELECT * FROM "+m_user+".quocgia");
			cboQG_NN.DisplayMember="tenqg";
			cboQG_NN.ValueMember="maqg";
			cboQG_NN.DataSource=ds.Tables[0];
			DataSet ds1 = ds.Copy();
			DataRow r = ds1.Tables[0].NewRow();
			r["maqg"]="";
			r["tenqg"]="";
			ds1.Tables[0].Rows.InsertAt(r,0);
			cboQG_NN.SelectedIndex=-1;

			DataSet dss=mDB.get_data("SELECT * FROM "+m_user+".dmThoiGian");
			cboDV_NN.DisplayMember="ten";
			cboDV_NN.ValueMember="ten";
			cboDV_NN.DataSource=dss.Tables[0];
			DataSet ds2 = dss.Copy();
			DataRow rr = ds2.Tables[0].NewRow();
			rr["ten"]="";
			rr["ten"]="";
			ds2.Tables[0].Rows.InsertAt(rr,0);
			cboDV_NN.SelectedIndex=-1;
		}

		private void txtDN_NN_Validated(object sender, System.EventArgs e)
		{
            txtDN_NN.Text = txtDN_NN.Text.Trim();
            if (txtDN_NN.Text == "  /  /")
            {
                return;
            }
            if(!mDB.kiemtrangayhople(txtDN_NN.Text.Trim()))
			{
				txtDN_NN.Focus();
				return ;
			}
		}		
        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                DataRowView arv = (DataRowView)(dataGridView1.CurrentRow.DataBoundItem);
                txtN_NN.Text = arv["nam"].ToString();
                cboQG_NN.SelectedValue = arv["maqgia"].ToString();
                txtTG_NN.Text = arv["t_gian"].ToString();
                cboDV_NN.SelectedValue = arv["dvtgian"].ToString();
                txtTN_NN.Text = arv["tu_ngay"].ToString();
                txtDN_NN.Text = arv["den_ngay"].ToString();
                txtCV_NN.Text = arv["lamgi"].ToString();
                txtid.Text = arv["id"].ToString();
            }
            catch
            {
            }
            Ena_control(false);            
            btn_sua.Enabled = admin;
            btn_huy.Enabled = admin;
        }

        private void dataGridView1_CurrentCellChanged(object sender, EventArgs e)
        {
            dataGridView1_CellClick(null, null);
        }

        private void btn_thoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btn_sua_Click(object sender, EventArgs e)
        {
            Ena_control(false);
            Ena_textbox(true);
            txtN_NN.Focus();
            flag = 1;
            SendKeys.Send("{F4}");
        }

        private void btn_them_Click(object sender, EventArgs e)
        {
            Ena_control(false);
            Ena_textbox(true);
            clear_Text();
            txtN_NN.Focus();
            flag = 0;
            
        }

        private void btn_luu_Click(object sender, EventArgs e)
        {
            saveData();
            flag = 0;
        }

        private void btn_huy_Click(object sender, EventArgs e)
        {
            string ma_nv, quoc_gia, dvtg, t_ngay, d_ngay, sql = "";
            decimal id = decimal.Parse(txtid.Text.Trim());
            string nam_ = "", thoi_gian = "";
            ma_nv = lblMasoNVCT.Text;
            try
            {
                int i = dataGridView1.CurrentCell.RowIndex;
                DialogResult dr = MessageBox.Show("Bạn có muốn hủy nhân viên này không", AccessData.Msg, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dr == DialogResult.Yes)
                {
                    nam_ = txtN_NN.Text;
                    quoc_gia = cboQG_NN.SelectedValue.ToString();
                    thoi_gian = txtTG_NN.Text;

                    sql = "DELETE  FROM " + m_user + ".xuatcanh ";
                    sql += " WHERE id=" + id + " ";
                    mDB.Execute_data(sql);
                    load_griddinuocngoai();
                    Ena_control(true);
                    flag = 0;
                }
            }
            catch { }
        }

        private void btn_them_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                txtN_NN.Focus();
        } 
        private void btn_luu_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                btn_them.Focus();
        }

        private void frmNuocNgoai_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Alt && e.KeyCode == Keys.T)
            {
                btn_them_Click(null, null);
            }
            if (e.Alt && e.KeyCode == Keys.S)
            {
                btn_sua_Click(null, null);
            }
            if (e.Alt && e.KeyCode == Keys.H)
            {
                btn_huy_Click(null, null);
            }
            if (e.Alt && e.KeyCode == Keys.L)
            {
                btn_luu_Click(null, null);
            }
            if (e.Alt && e.KeyCode == Keys.B)
            {
                btn_boqua_Click(null, null);
            }
            if (e.Alt && e.KeyCode == Keys.K)
            {
                btn_thoat_Click(null, null);
            }
        }
 
	}
}
